﻿@{
    ViewData["Title"] = "内敛匹配关键词导入";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
@section css{
    <style>
        .layui-form-item  {
           margin-top:20px;
        }
    </style>
}
<form class="layui-form" action="" lay-filter="keyword-edit">
    <div class="layuimini-container layuimini-page-anim">
        <div class="layuimini-main" style="height:160px;">
             <span style="color:red">注:如果没有导入模板,可选择生成导入模板,另外不要将excel数据存放到网站根目录</span>
            
            <div class="layui-form layuimini-form">
                 <div class="layui-form-item">                 
                  <div class="layui-input-block">  <button   class="layui-btn layui-btn-normal" lay-submit lay-filter="saveBtn">生成导入模板</button></div>                   
                </div>
                 <div class="layui-form-item">
                    <label class="layui-form-label">选择数据:</label>
                    <div class="layui-upload">
                        <button type="button" class="layui-btn" id="test2">导入Excel数据</button>
                        <div class="layui-input-block">
                        
                    </div>
                        <div class="layui-upload-list" >
                                <img class="layui-upload-img" id="demo2" >
                                <input type="hidden" id="logo" name="logo" class="layui-input" >
                        </div>
                    </div>
                </div>                
               
            </div>
        </div>
    </div>
</form>
@section js{
    <script>
            layui.use(['form', 'common','upload'], function () {
                var form = layui.form,
                    $ = layui.$,
                     upload = layui.upload,
                    apiUtil = layui.common;              
                var parentIndex =  parent.layer.getFrameIndex(window.name);                    
                form.render();

                 var obj=function(idDom,imgDom,inputDom,fileDirectory){
                   var model= {
                        elem: "#"+idDom
                        , accept: 'file' //普通文件
                        , url: apiUtil.apiUrl() + 'cms/Keyword/Import'
                        , before: function (obj) {
                            //预读本地文件示例，不支持ie8
                            obj.preview(function (index, file, result) {
                              
                            });
                        }
                         ,method:"post"
                         ,data:{
                             directory:function () {
                                        return fileDirectory;
                                    },
                         }
                        , done: function (res) { 
                             layer.msg(res.msg);   
                            setTimeout(function(){                               
                                parent.layer.close(parentIndex);
                            },600);      
                        }
                    }
                    return model;
                };
                 upload.render(
                 obj("test2","demo2","logo","cms")
                );
                //监听提交
                form.on('submit(saveBtn)', function (data) {       
                     window.location.href=apiUtil.apiUrl()+"cms/keyword/GenerateImportTemplate";
                    return false;
                });
            });
    </script>

}